package com.itheima.mapper;

import com.itheima.pojo.Emp;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

/**
 * 员工管理
 */
@Mapper
public interface EmpMapper {


    /**
     * Select count long.
     *
     * @param name   the name
     * @param gender the gender
     * @param begin  the begin
     * @param end    the end
     * @return the long
     */
    Long selectCount(String name, Short gender, LocalDate begin, LocalDate end);

    /**
     * Select list list.
     *
     * @param name   the name
     * @param gender the gender
     * @param begin  the begin
     * @param end    the end
     * @return the list
     */
//    List<Emp> selectList(String name, Short gender, LocalDate begin, LocalDate end, int index, Integer pageSize);
    List<Emp> selectList(String name, Short gender, LocalDate begin, LocalDate end);

    /**
     * Remove batch.
     *
     * @param ids the ids
     */
    void removeBatch(List<String> ids);

    /**
     * Select count by dept id integer.
     *
     * @param deptId the dept id
     * @return the integer
     */
    @Select("select count(*) from emp where dept_id = #{deptId}")
    Integer selectCountByDeptId(Integer deptId);

    /**
     * Insert.
     *
     * @param emp the emp
     */
    void insert(Emp emp);

    /**
     * Select count by username integer.
     *
     * @param username the username
     * @return the integer
     */
    @Select("select count(*) from emp where username = #{username}")
    Integer selectCountByUsername(String username);

    /**
     * Select by id emp.
     *
     * @param id the id
     * @return the emp
     */
    @Select("select * from emp where id = #{id}")
    Emp selectById(Integer id);

    /**
     * Update by id.
     *
     * @param emp the emp
     */
    void updateById(Emp emp);

    /**
     * Select count by username not id integer.
     *
     * @param username the username
     * @param id       the id
     * @return the integer
     */
    @Select("select count(*) from emp where username = #{username} and id != #{id} ")
    Integer selectCountByUsernameNotId(String username, Integer id);

    @Select("select * from emp where username = #{username}")
    Emp selectOneByUsername(String username);

    @Delete("delete from emp where dept_id = #{deptId}")
    void deleteByDeptId(Integer deptId);
}
